package leetcode.method.pointer;

import java.util.Arrays;

public class Program26RemoveRepeatElement {
    public Program26RemoveRepeatElement() {
    }

    public int removeDuplicates(int[] nums) {
        if (nums.length == 1) {
            return 1;
        }
        Arrays.sort(nums);
        int i = 0, j = 1;
        while (j < nums.length) {
            if (nums[j] != nums[i]) {
                nums[i + 1] = nums[j];
                i++;
            }
            j++;
        }
        return i + 1;
    }

    public static void main(String[] args) {
        Program26RemoveRepeatElement myStack = new Program26RemoveRepeatElement();
//        int[] nums = new int[]{0,1,2,2,3,0,4,2};
//        int[] nums = new int[]{3,2,2,3};
        int[] nums = new int[]{0,0,1,1,1,2,2,3,3,4};
        System.out.println(myStack.removeDuplicates(nums)); // 返回
    }
}
